# 用类封装一个mymath类，实现加减乘除幂开方
class MyMath:
    def add(self, a, b):
        return a + b

    def sub(self, a, b):
        return a - b

    def mul(self, a, b):
        return a * b

    def div(self, a, b):
        return a / b

    def pow(self, a, b):
        return a ** b

    def squ(self, a):
        return a ** 0.5
a = MyMath()
a.add(2, 3)
print(a)


# 创建一个类，创建多个实例
class Ball:
    def __init__(self, sort, year):
        self.sort = sort
        self.year = year

    def bounce(self):
        print(f"{self.sort} is bouncing.")

    def roll(self):
        print(f"{self.sort} rolled.")
# 实例
my_ball = Ball('football', 0.5)
print(f"我买了一个{my_ball.sort}.")
print(f"这个足球买了{my_ball.year}年了.")

my_ball.bounce()
my_ball.roll()


your_ball = Ball('basketball', 1)
print(f'你的{your_ball.sort}质量真好.')
print(f'都买了{your_ball.year}年了，还这么新.')



# 创建子类
class FootBall(Ball):
    def __init__(self, sort, year):
        super(FootBall, self).__init__(sort, year)
        self.size = 20

    def chicun(self):
        print(f'我新买的球的尺寸是{self.size}。')

my_newball = FootBall('football', 0)
my_newball.chicun()